package Month10.day1009;

public class TestString5 {
    public static void main(String[] args) {
        //先是用String创建对象然后调用字符构造器再转回String
        String s1 = "开始拼接";
        long start = System.currentTimeMillis();//获取开始毫秒值
        for (int i = 0; i < 10000; i++) {
            s1 += i;
        }
        long end = System.currentTimeMillis();//获取结束毫秒值
        System.out.println(end - start);

        //再接着尝试StringBuffer
        StringBuffer s2 = new StringBuffer("开始拼接");
        start = System.currentTimeMillis();//获取开始毫秒值
        for (int i = 0; i < 1000000; i++) {
            s2.append(i);
        }
        end = System.currentTimeMillis();//获取结束毫秒值
        System.out.println(end - start);

        //再接着尝试StringBuilder
        StringBuilder s3 = new StringBuilder("开始拼接");
        start = System.currentTimeMillis();//获取开始时间
        for (int i = 0; i < 1000000; i++) {
            s3.append(i);
        }
        end = System.currentTimeMillis();//获取结束时间
        System.out.println(end - start);
    }
}
